package com.devshephard.rpcframework.servletsync.service.impl;


import com.devshephard.rpcframework.servletsync.service.SyncServlet;

import javax.servlet.AsyncContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public abstract class AbsSyncServletImpl implements SyncServlet {


    @Override
    public void execute(HttpServletRequest request, HttpServletResponse response) {

        AsyncContext asyncContext = request.startAsync();

        Runnable runnable = () -> {
            try {
                asyncContext.getResponse().getWriter().write(this.callBack() +"Hello World!");
            } catch (IOException e) {
                e.printStackTrace();
            }
            asyncContext.complete();

        };

        new Thread(runnable).start();

    }

}
